<?php

class RegisterWorker extends Worker{
	
	/**
	 * 注册接口
	 */
	public function register(){
		$runData = $this->getRunData();
		if(!isset($runData['loginName'],$runData['password'])){
			$this->socketWrite(array('code'=>0,'data'=>'参数不正确'));return;
		}
		$runData['jetton'] = $this->config->getKey("defuatJetton")->get();
		$userModel = $this->loadModel("User");			
		if($userModel->isExist(array("loginName"=>$runData['loginName']))){ //如果用户名被注册
			$this->socketWrite(array('code'=>0,'data'=>'用户名已被注册'));return;
		}
		$runData['salt']     = randStr(10);
		$runData['password'] = md5Password($runData['password'],$runData['salt']);
		$runData['ctime']    = time();
		$runData['state']    = 0;
		if(!($newUserId = $userModel->insert($runData))){
			$this->socketWrite(array('code'=>0,'data'=>'注册失败'));return;
		}
		//添加用户info表
		$runData['userID'] = $newUserId;
		$userInfoModel     = $this->loadModel("UserInfo");
		$userInfoModel->insert($runData);
		$this->socketWrite(array('code'=>1,'data'=>array('userid'=>$newUserId)));return;
	}
}